package com.aabbc.database.service.impl;

import com.aabbc.database.entity.UserInfo;
import com.aabbc.database.mapper.UserInfoMapper;
import com.aabbc.database.service.IUserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenhai
 * @since 2020-04-02
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService {

    /**
     * 编辑用户信息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void editUserInfo() {
        UserInfo userInfo = new UserInfo();
        userInfo.setGender(1);
        userInfo.setName("editUserInfo");
        this.save(userInfo);

        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(userInfo);
        UserInfo entity = super.getOne(queryWrapper);
        entity.setName("edit");
        super.saveOrUpdate(entity);

        super.list();

        if("".equalsIgnoreCase("")){
            throw new RuntimeException();
        }

        queryWrapper.setEntity(entity);
        super.remove(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(UserInfo entity) {
        return super.save(entity);
    }
}
